package com.icss.ah.custMsg.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CustMessageService {
	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;
	
	private final Logger errlog = Logger.getLogger("E");
	private final Logger infolog = Logger.getLogger("I");
	
	/**
	 * 查询消费者留言列表
	 * @param map
	 * @return
	 */
	public List<Map> queryCustMsgList(HashMap map) {
		List<Map> list = new ArrayList<Map>();
		try{
			list = sqlSessionTemplate.selectList("CustMessageBean.queryCustMsgList", map);
			infolog.info("CustMessageService|queryCustMsgList|list:"+list);
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("CustMessageService|queryCustMsgList", ex);
		} 
		return list == null ? new ArrayList<Map>() : list;
	}

	/**
	 * 查询消费者留言总记录数
	 * @param map
	 * @return
	 */
	public long queryCustMsgCount(HashMap map) {
		Long reValue = 0l;
		try {
			reValue = (Long)sqlSessionTemplate.selectOne("CustMessageBean.queryCustMsgCount", map);
			infolog.info("CustMessageService|queryCustMsgCount|reValue:"+reValue);
		} catch (Exception e) {
			e.printStackTrace();
			errlog.error("CustMessageService|queryCustMsgCount", e);
		} 
		return reValue;
	}
	
	/**
	 * 保存留言回复信息
	 * @param map
	 * @return
	 */
	public boolean saveReply(HashMap map) {
		boolean reValue = false;
		try {
			int f = sqlSessionTemplate.insert("CustMessageBean.saveReply",map);
			sqlSessionTemplate.update("CustMessageBean.updateStatus",map);
			reValue = true;
			infolog.info("CustMessageService|saveReply|reValue:"+reValue);
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("CustMessageService|saveReply", ex);
		} 
		return reValue;
	}
	
	/**
	 * 查询店铺信息
	 * @param map
	 * @return
	 */
	public HashMap queryShopMap(HashMap<String, Object> map) {
		HashMap reMap = new HashMap();
		try {
			reMap = (HashMap)sqlSessionTemplate.selectOne("CustMessageBean.queryShopMap",map);
			infolog.info("CustMessageService|queryShopMap|reMap:"+reMap);
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("CustMessageService|queryShopMap", ex);
		} 
		return reMap = reMap == null ? new HashMap() : reMap;
	}
	/**
	 * 查询消费者留言信息
	 * @param map
	 * @return
	 */
	public HashMap queryMessageMap(HashMap<String, Object> map) {
		HashMap reMap = new HashMap();
		try {
			reMap = (HashMap)sqlSessionTemplate.selectOne("CustMessageBean.queryMessageMap",map);
			infolog.info("CustMessageService|queryMessageMap|reMap:"+reMap);
		} catch (Exception ex) {
			ex.printStackTrace();
			errlog.error("CustMessageService|queryMessageMap", ex);
		} 
		return reMap = reMap == null ? new HashMap() : reMap;
	}

}
